package main

import (
	"fmt"
	"os"
)

const N int = 1e6

var count int = 0

func main() {
	digits := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	sorts := make([]int, 0, len(digits))
	permutation(sorts, digits)
}

// permutation count计数，初始值为0;n
func permutation(sorts, digits []int) {
	lenOfDigits := len(digits)
	if lenOfDigits == 1 {
		count++
		if count == N {
			sorts = append(sorts, digits[0])
			fmt.Println(sorts)
			os.Exit(0)
		}
	}
	for i := 0; i < lenOfDigits; i++ {
		nextSorts := sorts
		nextSorts = append(nextSorts, digits[i])
		nextDigits := make([]int, lenOfDigits-1)
		for j := 0; j < lenOfDigits; j++ {
			if j < i {
				nextDigits[j] = digits[j]
			} else if j > i {
				nextDigits[j-1] = digits[j]
			}
		}
		if count < N {
			permutation(nextSorts, nextDigits)
		}
	}
}
